import {
  methods,
  request,
} from '@/utils/request';//设置自己的request路径

const actions = {
  getMessageList: {
    name: 'getMessageList',
    url: '/api/summercamp/notice/getteacher/',//后端接口
  },
  getDetialList: {
    name: 'getDetialList',
    url: '/api/summercamp/notice/getnoticereceivedetail/',//后端接口
  },
  getStudentListforGroup: {
    name: 'getStudentListforGroup',
    url: '/api/cluster/preview',//后端接口
  },
  getOptions: {
    name: 'getOptions',
    url: '/api/summercamp/notice/teachermanager',//后端接口
  },
  getNoticeDetail: {
    name: 'getNoticeDetail',
    url: '/api/freshSystem/student/selectNotify',//后端接口
  },
  setGroupByGroup: {
    name: 'setGroupByGroup',
    url: '/api/cluster/build',//后端接口
  },
  setFeedBack: {
    name: 'setFeedBack',
    url: '/api/activity/addFeedback',//后端接口
  },
  deleteList: {
    name: 'deleteList',
    url: '/api/summercamp/notice/teacher/deleteCluster/',//后端接口
  },
  getStudentRegister: {
    name: 'getStudentRegister',
    url: '/api/stuinfo/ifreported/',//后端接口
  },
  getStuBaseInfo: {
    name: 'getStuBaseInfo',
    url: '/api/stuinfo/teagetbase/',//后端接口
  },
  getStuFamilyInfo: {
    name: 'getStuFamilyInfo',
    url: '/api/stuinfo/teagetfamily/',//后端接口
  },
  postMethod: {
    name: 'postMethod',
    url: '/postMethod',
  }


};
const customRequest = (
  action: any,
  token: string = '',
  formdata: any = null,
) => {
  const options: any = {
    headers: {
      'Content-Type': 'application/json;charset=utf-8',
      Accept: 'application/json',
      Authorization: localStorage.getItem("token") ? localStorage.getItem("token") : '',
    }
  };
  let url = action.url;
  switch (action.name) {
    case actions.getMessageList.name:
      options['method'] = methods.get;
      url += formdata
      break;
    case actions.getDetialList.name:
      options['method'] = methods.get;
      url += formdata
      break;
    case actions.getOptions.name:
      options['method'] = methods.get;
      break;
    case actions.getStudentListforGroup.name:
      options['method'] = methods.post;
      options['body'] = JSON.stringify(formdata);
      break;
    case actions.getNoticeDetail.name:
      options['method'] = methods.get;
      url += '?id=' + formdata
      break;
    case actions.setGroupByGroup.name:
      options['method'] = methods.post;
      options['body'] = JSON.stringify(formdata);
      break;
    case actions.setFeedBack.name:
      options['method'] = methods.post;
      options['body'] = JSON.stringify(formdata);
      break;
    case actions.deleteList.name:
      options['method'] = methods.delete;
      url += formdata
      break;
    case actions.getStudentRegister.name:
      options['method'] = methods.get;
      url += formdata
      break;
    case actions.postMethod.name:
      options['method'] = methods.post;
      options['body'] = JSON.stringify(formdata);
      break;
    case actions.getStuBaseInfo.name:
      options['method'] = methods.get;
      url += formdata
      break;
    case actions.getStuFamilyInfo.name:
      options['method'] = methods.get;
      url += formdata
      break;

    default:
  }
  return request(url, options);
};

export function getMessageList(token: any, formdata: any) {
  return customRequest(actions.getMessageList, token, formdata);
}
export function getDetialList(token: any, formdata: any) {
  return customRequest(actions.getDetialList, token, formdata);
}
export function getStudentListforGroup(token: any, formdata: any) {
  return customRequest(actions.getStudentListforGroup, token, formdata);
}
export function getOptions(token: any, formdata: any) {
  return customRequest(actions.getOptions, token, formdata);
}
export function getNoticeDetail(token: any, formdata: any) {
  console.log(formdata)
  return customRequest(actions.getNoticeDetail, token, formdata);
}
export function setGroupByGroup(token: any, formdata: any) {
  return customRequest(actions.setGroupByGroup, token, formdata);
}
export function setFeedBack(token: any, formdata: any) {
  return customRequest(actions.setFeedBack, token, formdata);
}
export function getStuBaseInfo(token: any, formdata: any) {
  return customRequest(actions.getStuBaseInfo, token, formdata);
}
export function getStuFamilyInfo(token: any, formdata: any) {
  return customRequest(actions.getStuFamilyInfo, token, formdata);
}
export function deleteList(token: any, formdata: any) {
  return customRequest(actions.deleteList, token, formdata);
}
export function getStudentRegister(token: any, formdata: any) {
  return customRequest(actions.getStudentRegister, token, formdata);
}
export function postMethod(token: any, formdata: any) {
  return customRequest(actions.postMethod, token, formdata);
}
